package net.uman.service;

import java.util.ArrayList;
import java.util.List;

import net.uman.dao.ArticleDao;
import net.uman.entity.Article;
import net.uman.framework.modules.orm.Page;
import net.uman.framework.modules.orm.PropertyFilter;
import net.uman.util.Constants;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ArticleManager extends Manager {
	@Autowired
	private ArticleDao articleDao;
	
	public void getArticlePage(Page<Article> page,List<PropertyFilter> filters){
		articleDao.findPage(page, filters);
	}
	
	public  Article get(Long id){
		return articleDao.get(id);
	}
	
	public void insertNewsArticle(Article entity){
		articleDao.save(entity);
	}
	
	public void delete(Long id){
		articleDao.delete(id);
	}
	
	/**
	 * 前端新闻
	 * @return
	 */
	public  List<Article>  getFrontNews(){
		Page<Article> newsPage = new Page<Article>(10);
		newsPage.setPageNo(1);
		newsPage.setOrderBy("id");
		newsPage.setOrder(Page.DESC);
		List<PropertyFilter> filters = new ArrayList<PropertyFilter>();
		filters.add(new PropertyFilter("filter_EQI_type",String.valueOf(Constants.ARTICLE_TYPE_NEWS)));
		getArticlePage(newsPage, filters);
		return newsPage.getResult();
	}
}
